package com.ruoyi.produce.base.design.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.base.design.domain.ProduceDesign;
import com.ruoyi.produce.base.design.service.IProduceDesignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品设计信息
 *
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/produce/design")
@Api(value = "产品设计信息模块", tags = "产品设计信息接口")
public class ProduceDesignController extends BaseController {

    @Autowired
    private IProduceDesignService produceDesignService;

    /**
     * 获取产品设计列表
     * @param produceDesign
     * @return
     */
    @ApiOperationSupport(includeParameters = {"ProduceDesign.produceId", "ProduceDesign.designId", "ProduceDesign.createTime"})
    @ApiOperation(value = "获取产品设计列表",notes = "查询所有产品设计信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ProduceDesign produceDesign){

        startPage();
        List<ProduceDesign> produceDesignList = produceDesignService.selectProduceDesignList(produceDesign);

        return getDataTable(produceDesignList);
    }

    /**
     * 导出产品设计
     * @param produceDesign
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody ProduceDesign produceDesign)
    {
        List<ProduceDesign> produceDesignList = produceDesignService.selectProduceDesignList(produceDesign);
        ExcelUtil<ProduceDesign> util = new ExcelUtil<ProduceDesign>(ProduceDesign.class);
        return util.exportExcel(produceDesignList, "产品设计数据");
    }

    /**
     * 新增产品设计
     * @param produceDesign
     * @return
     */
    @ApiOperation(value = "新增产品设计", notes = "新增产品设计")
    @ApiImplicitParam(name = "produceDesign", value = "新增产品设计", dataType = "ProduceDesign")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody ProduceDesign produceDesign){

        return toAjax(produceDesignService.insertProduceDesign(produceDesign));
    }

    /**
     * 修改产品设计
     * @param produceDesign
     * @return
     */
    @ApiOperation(value = "修改产品设计", notes = "修改产品设计")
    @ApiImplicitParam(name = "produceDesign", value = "修改产品设计", dataType = "ProduceDesign")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody ProduceDesign produceDesign)
    {
        return toAjax(produceDesignService.updateProduceDesign(produceDesign));
    }

    /**
     * 删除产品设计
     * 仅修改删除标志位
     * @param produceDesign
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ProduceDesign produceDesign)
    {

        return toAjax(produceDesignService.updateProduceDesignDeleteFlag(produceDesign));
    }
}
